/*
Associated trayectory to an object in the trajectory analysis process.
*/


import java.util.Vector;
class AssociatedTrajectory{
	
    protected int frame; //frame in which the trajectory was associated to the object.
    protected String id_trajectory; //trajectory identificator.
    public float rol_satisfaction = 1; //satisfaction degree for rol constraints.
    public float spatial_satisfaction = 1; //satisfaction degree for spatial constraints.
    public float temporal_satisfaction = 1; //satisfaction degree for temporal constraints.
    public float satisfaction_degree=1;
    
    Vector<Zone> v_sequence; //sequence of covered areas.
    
    public AssociatedTrajectory(int frame, String trajectory, Zone z){
	this.frame = frame;
	this.id_trajectory = trajectory;
	v_sequence = new Vector();
	v_sequence.add(z);
    }//end constructor

    public int getFrame(){return this.frame;}
    public String getId(){return this.id_trajectory;}
    public Zone getLastZone(){
	return this.v_sequence.elementAt(v_sequence.size()-1);
    }//end getLastZone

    public Zone getBeforeLastZone(){
	if(v_sequence.size()>=2)
	    return this.v_sequence.elementAt(v_sequence.size()-2);
	else
	    return null;
    }
    
    public String getSequence(){
	String out = "";
	for(int i=0;i<this.v_sequence.size();i++){
	    Zone z = (Zone)this.v_sequence.elementAt(i);
	    out += "| "+z.name + "("+z.membership_value+") ";
	}
	return out;
    }
    
    public void addZone(Zone z){
	this.v_sequence.add(z);
    }

    public void updateSpatialSatisfaction(){
	float media = 0;
	int items = 0;
	for(int i=0; i<v_sequence.size();i++){
	    Zone z = (Zone) v_sequence.elementAt(i);
	    media += z.membership_value;
	    items++;
	}
	this.spatial_satisfaction = media/items;
	this.updateSatisfactionDegree();
    }

    public void updateRoleSatisfaction(float value){
	this.rol_satisfaction = value;
	this.updateSatisfactionDegree();
    }
    public void updateTemporalSatisfaction(float value){
	this.temporal_satisfaction = value;
	this.updateSatisfactionDegree();
    }

    private void updateSatisfactionDegree(){
	float min = 1;
	if(this.rol_satisfaction < min)
	    min = this.rol_satisfaction;
	if(this.spatial_satisfaction < min)
	    min = this.spatial_satisfaction;
	if(this.temporal_satisfaction < min)
	    min = this.temporal_satisfaction;
	this.satisfaction_degree = min;
    }
}//end class
